	//라운드예약정보
	function clsScoreRecord_Reserv(){
		this.listData = null;
		this._HTMLDom = null;
		this.idx = 0;
		this.customHole = 18;
		this.errMsg = null;
		this._ERRMSG = {
			"_NO_COURSE": "코스정보를 입력하십시요"
			, "_NO_HOLE": "홀정보를 입력하십시요."	
		}
		this._init();	
	}
	
	clsScoreRecord_Reserv.prototype = {
		_init: function(){
			var $layer = $("section#my_score_record>section>form dl");
			this._HTMLDom = {
				"$layer":	$layer
			}	
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.dispaly();
		}
		, dispaly: function(){
			var $layer = this._HTMLDom["$layer"];
			var $select = $layer.find("select:eq(0)");
			var thisClass = this;
			
			$layer.find("select:eq(0)").empty();
		
			//라운트키, 코스,,홀, 일자, 요일, 시간			
			for(var i=0;i<this.listData.length;++i){
				var courseInfo = "직접입력";
				if(this.listData[i]["예약코드"]){	
					//예약정보
					var hole = this.listData[i]["홀1"] + this.listData[i]["홀2"];
					courseInfo = this.listData[i]["코스코드1"] +" / "+ hole +"H / "+ this.listData[i]["라운드정보"]["일자"] +"("+ this.listData[i]["라운드정보"]["요일"] +") "+ this.listData[i]["라운드정보"]["시간"];					
				}else {					
					//직접입력
					$layer.find("ul:eq(0) li:eq(2) div input").val(this.customHole);						
				}
				$select.append("<option value='#'>"+ courseInfo + "</option>");
				$select.selectmenu("refresh");
			}
			
			this.setIdx(this.idx);
			this.showTime(this.idx);
			$select.selectmenu();		
		}
		, setIdx: function(n){	
			this.idx = n;			
			var $layer = this._HTMLDom["$layer"];
			var hole = this.listData[n]["홀1"] + this.listData[n]["홀2"];
			
			$layer.find("select:eq(0) option").eq(n).prop("selected", true);
			$layer.find("select:eq(0)").selectmenu("refresh");
			$layer.find("ul:eq(1) div.input_cont:eq(0) p").html(this.listData[n]["라운드정보"]["일자"] +"("+ this.listData[n]["라운드정보"]["요일"] + ")");
			$layer.find("ul:eq(1) div.input_cont:eq(1) p").html(this.listData[n]["골프장코드"] + "&nbsp;" + this.listData[n]["코스코드1"]);
			$layer.find("ul:eq(1) div.input_cont:eq(2) p").html(hole + "&nbsp;H");
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var $select = $layer.find("select");						
			var n = $select.eq(0).find("option").index($select.eq(0).find("option:selected")) ;
			var result = null;			
			
			if(n==0){						
				//직접입력
				result = {
					"예약코드": ""
					, "라운드구분": n
					, "골프장코드": $layer.find("ul:eq(0) li:eq(1) div input").val()
					, "코스코드1": $layer.find("ul:eq(0) li:eq(2) div input").val()
					, "코스코드2": ""
					, "코스코드3": ""
					, "홀1":	$layer.find("ul:eq(0) li:eq(2) div input").val()
					, "홀2":	$layer.find("ul:eq(0) li:eq(2) div input").val()					
					, "라운드정보": {
						"년": $select.eq(1).find("option").index($select.eq(1).find("option:selected"))
						, "월": $select.eq(2).find("option").index($select.eq(2).find("option:selected"))
						, "일": $select.eq(3).find("option").index($select.eq(3).find("option:selected"))
						, "일자": this.$getSelectValue()	
						, "시간": ""
					}
				}
			}else {
				//예약정보
				result = {
					"예약코드": this.listData[n]["예약코드"]
					, "라운드구분": n
//					, "골프장코드": this.listData[n]["골프장코드"]
//					, "코스코드1": this.listData[n]["코스코드1"]
//					, "코스코드2": this.listData[n]["코스코드2"]
//					, "코스코드3": this.listData[n]["코스코드3"]
//					, "홀1":	this.listData[n]["코스코드홀1"]
//					, "홀2":	this.listData[n]["코스코드홀2"]					
//					, "라운드정보": {
//						"년": null
//						, "월": null
//						, "일": null
//						, "일자": this.listData[n]["라운드일자"]
//					}
				}
			}
			return result;	
		}
		, reload: function(thisData){
			var $layer = this._HTMLDom["$layer"];
			var $select = $layer.find("select");		
			
			this.idx = thisData["라운드구분"];
		
		 	if(this.idx=="0"){
				$select.eq(1).find("option").eq(thisData["라운드정보"]["년"]).prop("selected", true); $select.eq(1).selectmenu("refresh");
				$select.eq(2).find("option").eq(thisData["라운드정보"]["월"]).prop("selected", true); $select.eq(2).selectmenu("refresh");
				$select.eq(3).find("option").eq(thisData["라운드정보"]["일"]).prop("selected", true); $select.eq(3).selectmenu("refresh");
				$layer.find("ul:eq(0) li:eq(1) div input").val(thisData["골프장코드"]);
				this.customHole = thisData["홀1"];
			}
			
			this.$getSelected().trigger("change");
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			if(!$layer.find("ul:eq(0) li:eq(1) div input").val()){
				this.errMsg = this._ERRMSG["_NO_COURSE"];
				return false;	
			}else if(!$layer.find("ul:eq(0) li:eq(2) div input").val()){
				this.errMsg = this._ERRMSG["_NO_HOLE"];
				return false;	
			}
			return true;
		}
		, getError: function(){
			return this.errMsg;	
		}
		, showTime: function(n){
			if(n==0){
				this.$getUl().hide().eq(0).show();	
			}else {
				this.$getUl().hide().eq(1).show();	
			}
		}
		, $getUl: function(){
			return this._HTMLDom["$layer"].find("ul");	
		}
		, $getSelected: function(){
			return this._HTMLDom["$layer"].find("select");	
		}
		, $getSelectValue: function(){
			var $select = this._HTMLDom["$layer"].find("ul:eq(0) select");			
			var result = $select.eq(0).find("option:selected").html() + $select.eq(1).find("option:selected").html() + $select.eq(2).find("option:selected").html();			
			return result;
		}
	}
	
	//라운드입력정보
	function clsScoreRecord_Contents(){
			this._HTMLDom = null;
			this.listData = null;
			this.errMsg = null;
			this._ERRMSG = {
				"_NODATA" : "내용을 입력하여 주십시요."
			}
			this._init();
	}
	
	clsScoreRecord_Contents.prototype = {
		_init: function(){
			var $layer = $("section#my_score_record>section>form dl dd:eq(1)");
			this._HTMLDom = {
				"$layer": $layer	
				, "$element": $layer.find("img_area")
			}
			
			$layer.find("img_area").empty();
		}	
		, setData: function(thisData){			
			this.listData = thisData;
			this.display();
		}	
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("img_area").empty();
			
			$layer.find("textarea").html(this.listData["내용"]);
			
			for(var i=0;i<this.listData["이미지"];++i){
				$layer.append($element.clone(true));	
			}
			
			$layer.find("img_area>div").each(function(n){
				$(this).find("img").attr("src", thisClass.listData["이미지"][n]);
			});
		}
		, $getBtnPhoto: function(){
			return $("section#my_score_record>section dt div.bt a");
		}	
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			
			var szImg = "";			
			var szContents = $layer.find("textarea").val();
			
			for(var i=0;i<$layer.find("img_area>div").length;++i){
				if(szImg != "") szImg += ",";
				szImg = "NOT,NOT,"+ $(this).find("img").attr("src") + ",NOT";	
			}
			
			var result = {
				"이미지": szImg
				, "내용": szContents	
			}
			return result;
		}
		, isValid: function(){
			var val = this.getValue();
			if(!val["내용"]){
				this.errMsg = this._ERRMSG["_NODATA"];
				return false;
			}
			
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}	
	}
	
	//스코어카드
	function clsScoreRecord_Card(){
		this._HTMLDom = null;
		this.listData = null;
		this.errMsg = null;
		this._ERRMSG = {
			"_NOCOUNT" : "스코어카드가 옳바르지 않습니다."
			, "_NOCOURSEOUT": "OUT코스정보가 옳바르지 않습니다."
			, "_NOCOURSEIN" : "IN코스정보가 옳바르지 않습니다."
		}
		this._init();	
	}
	
	clsScoreRecord_Card.prototype = {
		_init: function(){
			var $layer = $("section#my_score_record>section dt.score_area");
			this._HTMLDom = {
				"$layer": $layer
			}	
		}
		, setCount: function(score){
			var $layer = this._HTMLDom["$layer"];						
			$layer.find("span.sc_count").html(score);
		}
		, $getBtnScoreCard: function(){
			return this._HTMLDom["$layer"].find("a");
		}
		, setData: function(thisData){
			this.listData = thisData;
			this.setCount(this.listData["스코어카드수"]);			
		}
		, getValue : function(){			
			return this.listData;	
		}
		, isValid: function(){
			
			if(!this.listData){
				this.errMsg = this._ERRMSG["_NOCOUNT"];
				return false;	
			}else if(!this.listData["스코어카드수"]){
				this.errMsg = this._ERRMSG["_NOCOUNT"];
				return false;	
			}else if(!this.listData["아웃코스"]){
				this.errMsg = this._ERRMSG["_NOCOURSEOUT"]
				return false;	
			}else if(!this.listData["인코스"]){
				this.errMsg = this._ERRMSG["_NOCOURSEIN"]
				return false;	
			}
			
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}	
	}
	
	//데이터연동		
	function clsComm_MyScoreRecord(){
		this.scoreSchedule = null;				
		this._init();
	}	
	clsComm_MyScoreRecord.prototype = {
		_init: function(){
			this.scoreSchedule = {
				"예약코드": null
				, "코스코드1": null
				, "코스코드2": null
				, "골프장코드": null
				, "골프장코스": null
				, "홀1": null
				, "홀2": null
				, "라운드일자": {
					 "년": null
					 ,"월": null
					 ,"일": null
					 , "일자": null
				}
				, "요일": null
				, "시간": null
			}
		}
//------------------------ 라운드스케줄정보------------------------//					
		, getScoreScheduleList: function(){
			var thisClass = this;
			var objJson = new MJson();
        	var cm = new ConnectionManager();
			
			objJson.putClient("userid", "golfin3");
			objJson.putPub("sid", "US001");
        	objJson.putPub("servicename", "getUserReservList");

        	cm.requestGet(objJson.getJsonString(), function(ret){
        	
				thisClass.scoreSchedule = [{
					"예약코드": null
					, "코스코드1": null
					, "코스코드2": null
					, "골프장코드": "직접입력"
					, "골프장코스": null
					, "홀1": null
					, "홀2": null
					, "라운드정보": {
						 "년": null
						 ,"월": null
						 ,"일": null
						 , "요일": null
						 , "시간": null
						 , "일자": null
					}
				}];
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					if(!items.length) items = new Array(items);
					
					for(var i=0;i<items.length;i++){
						var obj = items[i];
						var reserveTime = _util.nvl(obj["reservTime"]);
						
						thisClass.scoreSchedule.push({
							"예약코드": _util.nvl(obj["reservSeq"])
							, "코스코드1": _util.nvl(obj["courseInfoId1"])
							, "코스코드2": _util.nvl(obj["courseInfoId2"])
							, "골프장코드": _util.nvl(obj["golfclubId"])
							, "골프장코스": _util.nvl(obj["golfclubName"]) + "-" + _util.nvl(obj["courseInfoName"])
							, "홀1": _util.nvl(obj["holeCnt1"], 0)
							, "홀2": _util.nvl(obj["holeCnt2"], 0)
							, "라운드정보": {
								 "년": _util.nvl(obj["reservDate"]).substr(0, 4)
								 ,"월": _util.nvl(obj["reservDate"]).substr(4, 2)
								 ,"일": _util.nvl(obj["reservDate"]).substr(6, 2)
								 , "요일": "금"								 
								 , "일자": _util.nvl(obj["reservDate"]).substr(0, 8)
								 , "시간": _util.nvl(obj["reservDate"]).substr(8, 4)
							}							
						});
					}
				}
				
				thisClass.scoreSchedule.push({
					"예약코드": "D772"
					, "골프장코드": "골프장"
					, "코스코드1": "코스1"
					, "코스코드2": "코스2"
					, "코스코드3": "코스3"
					, "홀1":	9
					, "홀2":	9
					, "라운드구분": 1
					, "라운드정보": {
						"년": "2012"
						, "월": "07"
						, "일": "20"
						, "요일": "금"
						, "일자": "20120720"
						, "시간": "1930"						
					}
				});
				
				$(thisClass).trigger("evtFinishScheduleList");				
			}, function($err) {
				alert($err);
			});					
		}
		, getScoreScheduleListData: function(){
			return this.scoreSchedule;	
		}
//------------------------ 라운드스케줄정보------------------------//
//------------------------ 스코어등록------------------------//
		, insertScore:function(arg){			
			var thisClass = this;
			var objJson = new MJson();
        	var cm = new ConnectionManager();
			
			objJson.putClient("userid", "golfin3");
			objJson.putPub("sid", "US001");
        	objJson.putPub("servicename", "registScoreCard");
        	
        	objJson.putParameter("reservSeq", arg["예약코드"]);
        	objJson.putParameter("roundDate", arg["라운드정보"]["일자"]);
			objJson.putParameter("golfclubId", arg["골프장코드"]);
			objJson.putParameter("courseInfoId1", arg["코스코드1"]);
			objJson.putParameter("courseInfoId2", arg["코스코드2"]);
			objJson.putParameter("courseInfoId3", arg["코스코드3"]);
			objJson.putParameter("holeCnt1", arg["홀1"]);
			if(arg["라운드구분"]!="0"){
				objJson.putParameter("holeCnt2", arg["홀2"]);				
			}
			objJson.putParameter("holeCnt3", "");
			objJson.putParameter("fileSeq", arg["파일코드"]);
			objJson.putParameter("saveFileName", arg["파일명"]);
			objJson.putParameter("orgnFileName", arg["원본파일명"]);
			objJson.putParameter("contents", arg["내용"]);
			
			var outCard = arg["아웃코스"];
			var inCard = arg["인코스"];
			
			for(var i=0;i<outCard.length;++i){
				objJson.putParameter("par" + (i+1),  outCard[i]["파"]);
				objJson.putParameter("score" + (i+1),  outCard[i]["스코어"]);
			}
			
			for(var i=0;i<inCard.length;++i){
				objJson.putParameter("par" + (i+outCard.length+1),  inCard[i]["파"]);
				objJson.putParameter("score" + (i+outCard.length+1),  inCard[i]["스코어"]);
			}
			
        	cm.requestGet(objJson.getJsonString(), function(ret){
				
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"]=="00000"?true:false)
					, "메세지": (ret["msp"]["contents"]["serviceResult"]=="00000"?"스코어가 등록되었습니다.":"오류발생")
				}
				
				$(thisClass).trigger("evtFinishInsertScore", resData);
			}, function($err) {
				alert($err);
			});					
			
		}
//------------------------ 스코어등록------------------------//
	}
	
	//컨트롤파일
	function MyScoreRecord(){
	
		this.objComm = null;
		this.objScoreRecord_Reserv = null;
		this.objScoreRecord = null;
		this.objScoreRecord_Contents = null;
		this.objScoreRecord_Card = null;
	};
	
	MyScoreRecord.prototype = {
	    onPageShow : function() {
	    	$("a").attr("href", "").attr("data-rel", "");
	    	$("section#my_score_record>section a").attr("href", "");
	    	this._init();	    	
	    	
	    }
	    , _init: function(){	
	    	this.objComm = new clsComm_MyScoreRecord();	    	
	    	
	    	this.objScoreRecord_Reserv = new clsScoreRecord_Reserv();	    	
	      	this.objScoreRecord_Contents = new clsScoreRecord_Contents();
	      	this.objScoreRecord_Card = new clsScoreRecord_Card();
	      	
	      	this._role();
	      	
	      	this.getParam();  
	      	
	      	this._bind();
	    }
	    , _start: function(){
	    	//스케줄정보 조회
	      	this.objComm.getScoreScheduleList();
	      	this.spinStart();
	    }
		 , _bind: function(){
		 	var thisClass = this;
		 	
		 	//스케줄조회 완료이벤트
		 	$(this.objComm).bind("evtFinishScheduleList", function(event){
		 		var thisData = thisClass.objComm.getScoreScheduleListData();
		 		thisClass.objScoreRecord_Reserv.setList(thisData);
		 		thisClass.spinEnd();
		 	});		 			 	
		 	
		 	//스코어등록 완료 이벤트
		 	$(this.objComm).bind("evtFinishInsertScore", function(event, resData){
		 		alert(resData["메세지"]);
		 		if(resData["응답코드"]){
		 			//초기화
		 			_gf.MYPAGE_DATA = null;
		 			$.mobile.changePage("my_score.html","slide",true);
		 		}
		 		
		 		thisClass.spinEnd();
		 	});
		 	
		 	//라운드정보변경 이벤트
		 	this.objScoreRecord_Reserv.$getSelected().change(function(event){
		 		var $select = thisClass.objScoreRecord_Reserv.$getSelected().eq(0);		 		
		 		var n = $select.find("option").index($select.find("option:selected"));
		 		
		 		thisClass.objScoreRecord_Reserv.showTime(n);
		 		if(n != 0){
		 			thisClass.objScoreRecord_Reserv.setIdx(n);	
		 		}		 		
			});
			
		 	//스코어카드수정
		 	this.objScoreRecord_Card.$getBtnScoreCard().click(function(event){		 		
		 		
		 		//var $select = thisClass.objScoreRecord_Reserv.$getSelected().eq(0);		 		
		 		//var n = $select.find("option").index($select.find("option:selected"));
		 		
		 		var data1 = thisClass.objScoreRecord_Reserv.getValue();
				var data2 = thisClass.objScoreRecord_Contents.getValue();
				
				if(!data1["홀1"]){
					alert("홀정보가 입력되지 않았습니다.");	
					return;
				}else if(data1["홀1"] <= 0){
					alert("홀정보가 0보다 같거나 작습니다.");
					return;	
				}
				
	    		//<--초기화
		 		if(!_gf.MYPAGE_DATA) {
			 		_gf.MYPAGE_DATA  = {}
			 	}
			 	
		 		_gf.MYPAGE_DATA["예약코드"] = data1["예약코드"];
		 		_gf.MYPAGE_DATA["라운드구분"] = data1["라운드구분"];
		 		_gf.MYPAGE_DATA["라운드정보"] = {
		 			"년": data1["라운드정보"]["년"]
	    			, "월": data1["라운드정보"]["월"]
	    			, "일": data1["라운드정보"]["일"]
	    			, "일자": data1["라운드정보"]["일자"]
		 		}
		 		_gf.MYPAGE_DATA["골프장코드"] = data1["골프장코드"];
		 		_gf.MYPAGE_DATA["코스"] = data1["코스코드1"];
		 		_gf.MYPAGE_DATA["홀1"] = data1["홀1"];
		 		_gf.MYPAGE_DATA["홀2"] = data1["홀2"];
		 		_gf.MYPAGE_DATA["이미지"] = data2["이미지"];
		 		_gf.MYPAGE_DATA["내용"] = data2["내용"];
		 		_gf.MYPAGE_DATA["리턴페이지"] = "my_score_record.html";
			 	//초기화-->
			 			 		
		 		$.mobile.changePage("my_card_record.html","slide",true);		
		 	});
		 	
		 	//스코어등록
		 	$("section#my_score_record>section div.btn_type2 a").unbind("click").click(function(event){		 		
		 		var $select = thisClass.objScoreRecord_Reserv.$getSelected().eq(0);		 		
		 		var n = $select.find("option").index($select.find("option:selected"));		 		
		 		
		 		var reserv = thisClass.objScoreRecord_Reserv.getValue();
		 		var contents = thisClass.objScoreRecord_Contents.getValue();
		 		var card = thisClass.objScoreRecord_Card.getValue();
		 		
		 		if(n==0){
			 		if(!thisClass.objScoreRecord_Reserv.isValid()){
		 				alert(thisClass.objScoreRecord_Reserv.getError());
		 				return;
		 			}
	 			}
	 			
	 			if(!thisClass.objScoreRecord_Contents.isValid()){
	 				alert(thisClass.objScoreRecord_Contents.getError());
	 				return;	
	 			}else if(!thisClass.objScoreRecord_Card.isValid()){
	 				alert(thisClass.objScoreRecord_Card.getError());
	 				return;	
	 			}
		 	
		 		var submitData = {
						"예약코드": reserv["예약코드"]
						, "라운드구분": reserv["라운드구분"]
						, "라운드정보": reserv["라운드정보"]
						, "골프장코드": reserv["골프장코드"]
						, "코스코드1": reserv["코스코드1"]
						, "코스코드2": reserv["코스코드2"]
						, "코스코드3": reserv["코스코드3"]
						, "홀1":	reserv["홀1"]
						, "홀2":	reserv["홀2"]
						, "파일코드": contents["이미지"]
						, "파일명": ""
						, "원본파일명": ""
						, "내용": contents["내용"]
						, "아웃코스": card["아웃코스"]
						, "인코스": card["인코스"]						
		 		}
		 		
		 		thisClass.spinStart();
		 		thisClass.objComm.insertScore(submitData);
		 	
		 	});
		 	
		 	//사진첨부
		 	this.objScoreRecord_Contents.$getBtnPhoto().bind("click",function(event){
		 		alert("사진첨부");
		 	});	
		 	
		 	//이미지삭제		 	
		 	
		 	//메뉴
		 	$("section#my_score_record nav ul li a:eq(0)").click(function(event){
		 		event.preventDefault();		 		
		 		$.mobile.changePage( "../inc/navi.html","slide",true);
		 	});
		 	
		 	//알림
		 	$("section#my_score_record nav ul li:eq(1)").click(function(event){
		 		event.preventDefault();
		 		$.mobile.changePage("../inc/info_booking.html","slide",true);	
		 	});
		 		    	
		 	//전체스코어
		 	$("section#my_score_record>footer ul li:eq(0) a").click(function(event){
		 		event.preventDefault();	
		 		$.mobile.changePage("my_score.html","slide",true);	
		 	});
		 	
		 	//스코어등록
		 	$("section#my_score_record>footer ul li:eq(1) a").click(function(event){
		 		event.preventDefault();	
		 		$.mobile.changePage("my_score_record.html","slide",true);	
		 	});
		 	
		 	//나의스코어통계
		 	$("section#my_score_record>footer ul li:eq(2) a").click(function(event){
		 		event.preventDefault();	
		 		$.mobile.changePage("my_score_state.html","slide",true);	
		 	});
		}
		, getParam: function(){
	    	if(!_gf.MYPAGE_DATA) {
	    		_gf.MYPAGE_DATA = {
	    			"예약코드": null	
	    		};
	    	}
	    	
	    	if(_gf.MYPAGE_DATA["스코어카드"]){
	    		this.objScoreRecord_Reserv.reload(_gf.MYPAGE_DATA);
	    		this.objScoreRecord_Contents.setData(_gf.MYPAGE_DATA);
	    		this.objScoreRecord_Card.setData(_gf.MYPAGE_DATA["스코어카드"]);
	    	}
	    	
	    	this._start();
	    }
	    , setParam: function(key, val){
	    	if(!_gf.MYPAGE_DATA){	
	    		_gf.MYPAGE_DATA = new Object();
	    	}
	    	if(key !== 0 && !key) {
	    		_gf.MYPAGE_DATA[key] = null;
	    	}
	    	_gf.MYPAGE_DATA[key] = val;    	
	    }
	     , _role: function(){
	    		if(!_util.getLogin("로그인")){
	    			//alert("로그인 후 이용하실 수 있습니다.");		    			
	    			this.goNavi();		
	    			return;
	    		}
	   }
		, goNavi: function(){			
			$.mobile.changePage("../inc/navi.html","slide",true);
		}
		, spinStart: function(){		
			$.mobile.showPageLoadingMsg();			
		}
		, spinEnd: function(){			
	 		$.mobile.hidePageLoadingMsg();				
		}
	}